package com.lhy.wanandroid.ui.main

import android.view.MenuItem
import android.view.View
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.lhy.base.BaseFragmentAdapter
import com.lhy.base.BaseVmFragment
import com.lhy.demo.R
import com.lhy.demo.common.MyActivity
import com.lhy.demo.other.KeyboardWatcher
import com.lhy.demo.other.KeyboardWatcher.SoftKeyboardStateListener
import com.lhy.wanandroid.ui.main.home.HomeFragment
import kotlinx.android.synthetic.main.activity_home.*

class MianKotlinActivity :MyActivity(), SoftKeyboardStateListener,
        BottomNavigationView.OnNavigationItemSelectedListener{

    private lateinit var  pagerAdapter:BaseFragmentAdapter<BaseVmFragment>;

    override fun initData() {
        pagerAdapter=BaseFragmentAdapter<BaseVmFragment>(this)
        pagerAdapter.addFragment(HomeFragment.newInstance())

        vp_home_pager.adapter=pagerAdapter
        vp_home_pager.offscreenPageLimit=pagerAdapter.count
    }

    override fun getLayoutId(): Int = R.layout.activity_home

    override fun initView() {
        // 不使用图标默认变色
        bv_home_navigation.setItemIconTintList(null)
        bv_home_navigation.setOnNavigationItemSelectedListener(this)

        KeyboardWatcher.with(this)
                .setListener(this)
    }

    override fun onSoftKeyboardClosed() {
        bv_home_navigation.visibility=View.VISIBLE
    }

    override fun onSoftKeyboardOpened(keyboardHeight: Int) {
        bv_home_navigation.visibility=View.GONE
    }

    override fun onNavigationItemSelected(item: MenuItem): Boolean {
        when(item.itemId){
            R.id.menu_home -> pagerAdapter.setCurrentItem(HomeFragment::class.java)

            else -> return false
        }
        return false
    }

}